<!--
- Author:  LiShibin.
- Date:    2016/12/22.
- File:    登录测试
-->
<template>
  <div class="login-class">
    <div class="login">
      <div class="login-item">
        文件服务器host：<input type="text" v-model="fileServerHost">
      </div>
      <div class="login-item">
        文件服务器port：<input type="text" v-model="fileServerPort">
      </div>
      <div class="login-item">
        图片服务器host：<input type="text" v-model="imgServerHost">
      </div>
      <div class="login-item">
        图片服务器port：<input type="text" v-model="imgServerPort">
      </div>
      <div class="login-item">
        组织Id：<input type="text" v-model="orgId">
      </div>
      <div class="login-item">
        体系Id：<input type="text" v-model="sysId">
      </div>
      <div class="login-item">
        主题类型：<input type="text" v-model="theme">
      </div>
      <div class="login-item">
        账&nbsp;&nbsp;&nbsp;号：<input type="text" v-model="account">
      </div>
      <div class="login-item">
        密&nbsp;&nbsp;&nbsp;码：<input type="pwd" v-model="pwd">
      </div>
      <div class="login-action">
        <button class="login-action-sign" @click="sign">登录</button>
      </div>
    </div>
  </div>
</template>

<script>
  //  import { mapActions } from 'vuex'

  export default {
    data () {
      return {
        sysId: 'S90BA429D4E5248F1A432B97F247DD651', // 'S1292CCB6C7E44B1693DC4C6588B92ED6',
        orgId: '', // 'OA238FEE955D045C08F91342F042992A9',
        account: 'superAdmin', // admin123
        pwd: '12345678', // 12345678
        fileServerHost: '192.168.254.188',
        fileServerPort: '8003',
        imgServerHost: '192.168.254.188',
        imgServerPort: '8001',
        theme: '0' // '0' 为默认主题，‘1’ 为联通主题
      }
    },
    components: {},
    computed: {},
    mounted () {
    },
    methods: {
      sign () {
        this.$request.login(this.account, this.pwd).then(res => {
          if (this.$utils.isEmptyObject(res)) {
            this.$toast('账号或密码不正确')
            return
          }
          console.log('登录后返回的userId:', res.userId, res)
          window.localStorage.setItem('clientId', '2E7966B47EA04112BBC03F3B9992E6F7')
          window.localStorage.setItem('accessTokenKey', res.accessTokenKey)
          window.localStorage.setItem('accessToken', res.accessToken)
          window.localStorage.setItem('userId', res.userId)
          window.localStorage.setItem('sysId', 'S90BA429D4E5248F1A432B97F247DD651')
          // this.getOsys()
          this.$router.push('/relate')
        }).catch(e => {
          console.error(e)
        })
      },
      getOrg (sysId) {
        this.$request.getOrgList(sysId).then(response => {
          console.log('获取组织', response)
          window.localStorage.setItem('orgId', response[0].orgId)
        }).catch(e => {
          console.error(e)
        })
      },
      getOsys () {
        this.$request.getOsys().then(response => {
          console.log('获取体系', response)
          this.getOrg(response[0].sysId)
        }).catch(e => {
          console.error(e)
        })
      }
    }
  }
</script>

<style lang="less" rel="stylesheet/less">
  .login-class {
    .login {
      text-align: center;
      padding-top: 10rem;
      font-size: 1.4rem;

      &-item {
        margin-bottom: 1.5rem;

        input {
          height: 2.5rem;
          line-height: 2.5rem;
        }
      }

      &-action {
        &-sign {
          padding: 0.5rem 1.5rem;
        }
      }
    }
  }
</style>
